/**axios封装
 * 请求拦截、相应拦截、错误统一处理
 */
import axios from "axios";

// import QS from 'qs';
import { basegeoserver, baseswagger, weatherSwagger } from "../../public/mapconfig";

// export var baseUrl = window.api.baseUrl
// export var codeUrl = window.api.codeUrl

// export var geoserver = "http://192.168.0.122:8080";
// export var swagger = "http://192.168.0.122:8355";

export var geoserver = basegeoserver;
export var swagger = baseswagger;
export var weather = weatherSwagger;

// 请求超时时间
axios.defaults.timeout = 1000000;
// post请求头
axios.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8";
/**
 * get方法，对应get请求
 * @param {String} url [请求的url地址]
 * @param {Object} params [请求时携带的参数]
 */
export function Get(url, params, serviceName ) {
  return new Promise((resolve, reject) => {
    axios
      .get(url, {
        params: params,
      })
      .then((res) => {
        resolve(res.data);
      })
      .catch((err) => {
        reject(err.data);
        console.error(`get请求---${serviceName}---接口失败`);
      });
  });
}
/**
 * post方法，对应post请求
 * @param {String} url [请求的url地址]
 * @param {Object} params [请求时携带的参数]
 */
export function Post(url, params, serviceName ) {
  return new Promise((resolve, reject) => {
    axios
      .post(url, params)
      .then((res) => {
        resolve(res.data);
      })
      .catch((err) => {
        reject(err.data);
        console.error(`post请求---${serviceName}---接口失败`);
      });
  });
}
